import React, {Component} from 'react';
import {
  Layout,
  Menu,
  Breadcrumb,
  Modal,
  Form,
  Input,
  Select,
  DatePicker,
  Popconfirm,
  Card,
  Row,
  Col,
  Button,
  Radio,
  Dropdown,
  Icon,
  Upload,
  message,
  Table,
  Pagination,
  Checkbox
} from 'antd';
const FormItem = Form.Item;
const {Header, Content, Footer} = Layout;
import _ from 'underscore';
import WrapPage from './_wrap'
import styles from './main.less'
import { browserHistory,Link } from 'dva/router';
import * as UserModel from '../model/user';

 class _Page extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
      }
  handleSubmit = async (e) => {
        e.preventDefault();
        await UserModel.logout()
        message.success('你已经退出')
        browserHistory.push('/login')
    }
  render() {
    let user = JSON.parse(localStorage.user);
    if(!('user' in localStorage)){
           message.error('您需要重新登录');
           browserHistory.push('/login');
       }
    return (
      <WrapPage>
        <Row type="flex" justify="space-around" align="middle" >
        <Col span={4} offset={18}><Button style={{marginRight:20}} title="我的消息" type="primary"><Link to={"/message"} ><Icon type="message" /></Link></Button><Button title="修改" type="" style={{marginRight:20}}><Link to={"/me"} ><Icon type="edit" /></Link></Button><Button onClick={this.handleSubmit} title="退出" type=""><Icon type="logout" /></Button></Col>
        <div style={{marginBottom:30,marginTop:50}}>
          <Col span={12} offset={6}><h2>你好，{user.name}</h2></Col>
          <Col span={12} offset={6}><h2>手机号：{user.phone}</h2></Col>
          <Col span={12} offset={6}><h2>部门：{user.department}</h2></Col>
        </div>
        </Row>
      </WrapPage>
    );
  }
}

export default _Page
